package day13;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

//服务端
//案例:服务端和客户端的读写数据
public class Server1 {
    public static void main(String[] args) throws IOException {
        //1.创建服务端对象
        ServerSocket server = new ServerSocket(60000);

        while (true) {  //控制多人连接服务端
            System.out.println("开始执行");
            //2.等待客户端连接
            Socket client = server.accept();
            System.out.println(client);
            //3.获取输入(读取客户端的数据)和输出流(向客户端写数据)
            InputStream is = client.getInputStream();
            OutputStream os = client.getOutputStream();
            String msg = "连接成功了!\n";
            os.write(msg.getBytes());

            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String result = br.readLine();
            System.out.println("服务器端读取客户端的数据:" + result);
        }
    }
}
